enum SIZE {
    //% block="29*29"
    1,
    //% block="58*58"
    2
}

enum LINE {
    //% block="1"
    1,
    //% block="2"
    2,
    //% block="3"
    3,
    //% block="4"
    4
}

enum BTN {
    //% block="A"
    A,
    //% block="B"
    B,
    //% block="A+B"
    AB
}

//% color="#AA278D" iconWidth=50 iconHeight=40
namespace vs1838b {

   // //% block="如果引脚[PIN_DigitalWrite] 接收到红外信号?" blockType="boolean"
   // //% PIN_DigitalWrite.shadow="dropdown" PIN_DigitalWrite.options="PIN_DigitalWrite"  PIN_DigitalWrite.defl="PIN_DigitalWrite.1"
    //export function if_remote(parameter: any, block: any) {
    //     let rev_pin = parameter.PIN_DigitalWrite.code
    //    Generator.addInclude('vs1838b_include', '#include <IRremote.h>');
    //    Generator.addObject(`vs1838b_define`, ` `, `IRrecv irrecv_${rev_pin}(${rev_pin});\n\tdecode_results results_${rev_pin};\n\t`);
    //    Generator.addSetup(`vs1838b_${rev_pin}_begin`,`irrecv_${rev_pin}.enableIRIn();`);
    //    Generator.addCode(`irrecv_${rev_pin}.decode(&results_${rev_pin})`);
    //}
   // //% block="读取引脚[PIN_DigitalWrite] 红外接收值" blockType="reporter"
   // //% PIN_DigitalWrite.shadow="dropdown" PIN_DigitalWrite.options="PIN_DigitalWrite"  PIN_DigitalWrite.defl="PIN_DigitalWrite.1"
   // export function read_remote(parameter: any, block: any) {
   //      let rev_pin = parameter.PIN_DigitalWrite.code
   //     Generator.addCode(`results_${rev_pin}.value`);
    //}
    // //% block="等待引脚[PIN_DigitalWrite]接收下一个红外接收值" blockType="command"
    // //% PIN_DigitalWrite.shadow="dropdown" PIN_DigitalWrite.options="PIN_DigitalWrite"  PIN_DigitalWrite.defl="PIN_DigitalWrite.1"
    //export function wait_remote(parameter: any, block: any) {
    //     let rev_pin = parameter.PIN_DigitalWrite.code
    //    Generator.addCode(`irrecv_${rev_pin}.resume();`);
    //}
    //% block="读取引脚[PIN_DigitalWrite] 红外接收值" blockType="reporter"
    //% PIN_DigitalWrite.shadow="dropdown" PIN_DigitalWrite.options="PIN_DigitalWrite"  PIN_DigitalWrite.defl="PIN_DigitalWrite.1"
    export function remote(parameter: any, block: any) {
          let rev_pin = parameter.PIN_DigitalWrite.code
        Generator.addInclude('vs1838b_include', '#include <IRremote.h>');
        Generator.addObject(`vs1838b_define`, ` `, `IRrecv irrecv_${rev_pin}(${rev_pin});\n\tdecode_results results_${rev_pin};\n\t`);
        Generator.addObject(`vs1838b_define_${rev_pin}`, ` `, `long remote_${rev_pin}()
{
   if (irrecv_${rev_pin}.decode(&results_${rev_pin})) {
    long rev = results_${rev_pin}.value;
    irrecv_${rev_pin}.resume();
    return rev;
  }
  else{ return 0; }
}`);
        Generator.addSetup(`vs1838b_${rev_pin}_begin`,`irrecv_${rev_pin}.enableIRIn();`);
        Generator.addCode(`remote_${rev_pin}()`);
    }

}
